#ifndef __RECKON__IFILEIMPL_H__
#define __RECKON__IFILEIMPL_H__

#include "reckon/IFile.h"

namespace reckon {
	class TextFileImpl : public ITextFile
	{
	public:
		virtual bool close();

		//virtual bool open(IFile::open_mode mode);
		virtual bool openToRead();
		virtual bool openToWrite(IFile::file_encoding encoding = IFile::ansi);
		virtual bool openToAppend();

		virtual file_encoding getEncoding();

		virtual bool readLine(tstring& buf);
		virtual bool writeLine(const tstring& buf);

	public:
		TextFileImpl(
			LPCTSTR lpszPath, 
			IFile::open_mode mode, 
			IFile::file_encoding encoding);

		TextFileImpl(LPCTSTR lpszPath);

		virtual ~TextFileImpl();

	private:
		FILE* _open();
		IFile::file_encoding _checkBOM();
		bool _writeBOM();
		void _insertBOM();
		bool _checkPath();

		bool _readBytes(void* buff, u32 byteSize);
		bool _readLineA(tstring& buf);
		bool _readLineW(tstring& buf);

	private:
		tstring								_filePath;
		IFile::open_mode					_mode;
		IFile::file_encoding				_encoding;
		FILE*								_fp;
		bool								_bOpened;
	};
}

#endif // __RECKON__IFILEIMPL_H__